home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / jpsrc2.zip / JCSAMPLE.C < prev    next >
C/C++ Source or Header  |  1991-12-01  |  4KB  |  136 lines

  1. /*
  2.  * jcsample.c
  3.  *
  4.  * Copyright (C) 1991, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains subsampling routines.
  9.  * These routines are invoked via the subsample and
  10.  * subsample_init/term methods.
  11.  */
  12.  
  13. #include "jinclude.h"
  14.  
  15.  
  16. /*
  17.  * Initialize for subsampling a scan.
  18.  */
  19.  
  20. METHODDEF void
  21. subsample_init (compress_info_ptr cinfo)
  22. {
  23.   /* no work for now */
  24. }
  25.  
  26.  
  27. /*
  28.  * Subsample pixel values of a single component.
  29.  * This version only handles integral sampling ratios.
  30.  */
  31.  
  32. METHODDEF void
  33. subsample (compress_info_ptr cinfo, int which_component,
  34.        long input_cols, int input_rows,
  35.        long output_cols, int output_rows,
  36.        JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
  37.        JSAMPARRAY output_data)
  38. {
  39.   jpeg_component_info * compptr = cinfo->cur_comp_info[which_component];
  40.   int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  41.   long outcol;
  42.   JSAMPROW inptr, outptr;
  43.   INT32 outvalue;
  44.  
  45.   /* TEMP FOR DEBUGGING PIPELINE CONTROLLER */
  46.   if (output_rows != compptr->v_samp_factor ||
  47.       input_rows != cinfo->max_v_samp_factor ||
  48.       (output_cols % compptr->h_samp_factor) != 0 ||
  49.       (input_cols % cinfo->max_h_samp_factor) != 0 ||
  50.       input_cols*compptr->h_samp_factor != output_cols*cinfo->max_h_samp_factor)
  51.     ERREXIT(cinfo->emethods, "Bogus subsample parameters");
  52.  
  53.   h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  54.   v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  55.   numpix = h_expand * v_expand;
  56.   numpix2 = numpix/2;
  57.  
  58.   inrow = 0;
  59.   for (outrow = 0; outrow < output_rows; outrow++) {
  60.     outptr = output_data[outrow];
  61.     for (outcol = 0; outcol < output_cols; outcol++) {
  62.       outvalue = 0;
  63.       for (v = 0; v < v_expand; v++) {
  64.     inptr = input_data[inrow+v] + (outcol*h_expand);
  65.     for (h = 0; h < h_expand; h++) {
  66.       outvalue += (INT32) GETJSAMPLE(*inptr++);
  67.     }
  68.       }
  69.       *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  70.     }
  71.     inrow += v_expand;
  72.   }
  73. }
  74.  
  75.  
  76. /*
  77.  * Subsample pixel values of a single component.
  78.  * This version handles the special case of a full-size component.
  79.  */
  80.  
  81. METHODDEF void
  82. fullsize_subsample (compress_info_ptr cinfo, int which_component,
  83.             long input_cols, int input_rows,
  84.             long output_cols, int output_rows,
  85.             JSAMPARRAY above, JSAMPARRAY input_data, JSAMPARRAY below,
  86.             JSAMPARRAY output_data)
  87. {
  88.   if (input_cols != output_cols || input_rows != output_rows) /* DEBUG */
  89.     ERREXIT(cinfo->emethods, "Pipeline controller messed up");
  90.  
  91.   jcopy_sample_rows(input_data, 0, output_data, 0, output_rows, output_cols);
  92. }
  93.  
  94.  
  95. /*
  96.  * Clean up after a scan.
  97.  */
  98.  
  99. METHODDEF void
  100. subsample_term (compress_info_ptr cinfo)
  101. {
  102.   /* no work for now */
  103. }
  104.  
  105.  
  106.  
  107. /*
  108.  * The method selection routine for subsampling.
  109.  * Note that we must select a routine for each component.
  110.  */
  111.  
  112. GLOBAL void
  113. jselsubsample (compress_info_ptr cinfo)
  114. {
  115.   short ci;
  116.   jpeg_component_info * compptr;
  117.  
  118.   if (cinfo->CCIR601_sampling)
  119.     ERREXIT(cinfo->emethods, "CCIR601 subsampling not implemented yet");
  120.  
  121.   for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  122.     compptr = cinfo->cur_comp_info[ci];
  123.     if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  124.     compptr->v_samp_factor == cinfo->max_v_samp_factor)
  125.       cinfo->methods->subsample[ci] = fullsize_subsample;
  126.     else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  127.          (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0)
  128.       cinfo->methods->subsample[ci] = subsample;
  129.     else
  130.       ERREXIT(cinfo->emethods, "Fractional subsampling not implemented yet");
  131.   }
  132.  
  133.   cinfo->methods->subsample_init = subsample_init;
  134.   cinfo->methods->subsample_term = subsample_term;
  135. }
  136.